//TcpServer  和   TcpSocket  的测试文件
#include <iostream>
#include "tcpServer.h"
#include "tcpSocket.h"
#include "threadpool.h"

void handle(const daniel::TcpSocket::ptr& tcpSocket)
{
    std::cout<<"tcpthread ID:"<<std::this_thread::get_id()<<std::endl;
    std::string msg;
    tcpSocket->recvMsg(msg);
    std::cout<<"receive msg:"<<msg<<std::endl;
    tcpSocket->sendMsg("send msg:"+msg);
}


int main()
{
    daniel::TcpServer::ptr server(new daniel::TcpServer(8888));
    daniel::ThreadPool::ptr threadPool(new daniel::ThreadPool(4,8));
    while (true)
    {
        daniel::TcpSocket::ptr tcpSocket;
        tcpSocket.reset(server->acceptConnfd());
        if (tcpSocket==nullptr){
            continue;
        }
        threadPool->addTask(std::bind(&handle,tcpSocket));
    }
}